package com.taptech.doufu.db.offline;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

import com.taptech.doufu.constant.Constant;

public class OffLineDataBaseHelper extends SQLiteOpenHelper{

	public static final String DBNAME = "offline_db.db";
	public static final String TABLE_NAME = "offline_table";
	public OffLineDataBaseHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, DBNAME, null, Constant.DB_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		Cursor cursor = null;
		try {
			cursor = db.rawQuery(
					"SELECT * FROM sqlite_master WHERE type = ? AND name = ?",
					new String[] { "table", TABLE_NAME });
			if (cursor.moveToNext()) {
			} else {
				db.execSQL("CREATE TABLE " + TABLE_NAME + " ("+
						"_ID INTEGER PRIMARY KEY autoincrement, "
						+ "offline_novelid VARCHAR(1024), "
						+ "offline_url VARCHAR(1024), "
						+ "offline_name VARCHAR(1024), "
						+ "offline_status INTEGER, "
						+ "offline_time VARCHAR(1024)"
						+ ");");
			}
			cursor.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}
}
